﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Collections.ObjectModel;
namespace BallData
{
    public class FilterOdds : IListenFilter 
    {
        private MainUIControl uicontrol;

        public MainUIControl Uicontrol
        {
            get { return uicontrol; }
            set { uicontrol = value; }
        }
        public double hostx = 0.05;//亚盘主队水位差值
        public double vistx = 0.05;//亚盘客队水位差值
        public double hostx_o = 0.1;//欧盘主胜赔率
        public double pingx_o = 0.1;//欧盘平赔率
        public double visitgx_o = 0.1;//欧盘负赔率
        public double bigx = 0.1;//大球
        public double bigsmallx = 0.1;//大小球盘口
        public double smallx = 0.1;//小球
        public void OnListenFilter(Bet007_Match bi, Match_FilterItemBind fi, Bet007_AnalysisData ba)
        {
            //"让球","主队水位","客队水位","主胜","和局","客胜","大球","盘口","小球"
            #region 让球
            if (fi.bFilter && fi.szSelectFilterType == "让球")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    { 

                        String oddscn = OddsUntil.Goal2GoalCn(odds.odds_a);
                        if (Regex.IsMatch(fi.szFilter, "^[\u4e00-\u9fa5]+$"))//判断是否中文
                        {
                            if (oddscn == fi.szFilter)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {
                                    
                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;
                                

                            }
                        }
                        else
                        {
                            if (odds.host_a == fi.szFilter)
                            {
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;

                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {
                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));


                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;
                                
                            
                            }
                        }
                        
                    }
                
                }

            }
            #endregion
            #region 主队水位
            if (fi.bFilter && fi.szSelectFilterType == "主队水位")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    { 

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.host_a) - Convert.ToDouble(fi.szFilter)) < hostx)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {
                                    
                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;
                                
                                
                            }
                        }

                        
                    }
                
                }

            }
            #endregion
            #region 客队水位
            if (fi.bFilter && fi.szSelectFilterType == "客队水位")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.visit_a) - Convert.ToDouble(fi.szFilter)) < vistx)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 主胜
            if (fi.bFilter && fi.szSelectFilterType == "主胜")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.host_o) - Convert.ToDouble(fi.szFilter)) < hostx_o)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 和局
            if (fi.bFilter && fi.szSelectFilterType == "和局")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.ping_o) - Convert.ToDouble(fi.szFilter)) < pingx_o)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 客胜
            if (fi.bFilter && fi.szSelectFilterType == "客胜")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.lost_o) - Convert.ToDouble(fi.szFilter)) < visitgx_o)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 大球
            if (fi.bFilter && fi.szSelectFilterType == "大球")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.big) - Convert.ToDouble(fi.szFilter)) < bigx)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 盘口
            if (fi.bFilter && fi.szSelectFilterType == "盘口")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.bigsmall_odds) - Convert.ToDouble(fi.szFilter)) < smallx)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
            #region 小球
            if (fi.bFilter && fi.szSelectFilterType == "小球")
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                foreach (Bet007_WebOdds odds in ba.oddscurlist.Values)
                {
                    if (odds.timetype == "1" || odds.timetype == "2")//初盘,当前盘
                    {

                        if (Regex.IsMatch(fi.szFilter, "^[\\d\\.]+$"))//判断是否数字
                        {
                            if (Math.Abs(Convert.ToDouble(odds.small) - Convert.ToDouble(fi.szFilter)) < smallx)
                            {
                                // 默认取澳门盘比赛模板
                                MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                                if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                                {

                                    Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                                    {
                                        matchlist.Add(matchlistdatatemple);
                                        Uicontrol.NotifyFilterMatchOk();
                                    }));
                                }
                                else
                                {
                                    Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                                }
                                break;


                            }
                        }


                    }

                }

            }
            #endregion
        }
    }
}
